import 'package:chat/controller/group_manage_controller.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

final GroupManageController controller = Get.find();

class GroupManageScreen extends StatelessWidget {
  const GroupManageScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: const Text('群管理'),
        centerTitle: true,
        leading: IconButton(icon: const Icon(Icons.arrow_back_ios), onPressed: () => Get.back()),
      ),
      body: ListView(
        children: [
          _buildStaticItem('群管理员', '', () => {}),
          _divider(),
          _buildStaticItem('谁可以编辑群信息', '仅群主可操作', () => Get.toNamed('/addGroupScreen')),
          _buildStaticItem('谁可以添加群成员', '仅群主可操作', () => {}),
          _buildStaticItem('谁可以移除群成员', '仅群主可操作', () => {}),
          _divider(),
          _buildStaticItem('谁可以修改群成员资料', '群主或管理员可...', () => {}),
          Obx(
            () => _buildSwitchItem(
              '群聊邀请确认',
              switchValue: controller.inviteConfirmationEnabled.value,
              onChanged: (value) => controller.toggleTop(),
            ),
          ),
          _divider(),
          _buildStaticItem('转让群', '', () => {}),
        ],
      ),
    );
  }

  Widget _divider() {
    return Container(height: 10, color: Color(0XFFF2F3F7));
  }

  Widget _buildStaticItem(String title, String subtitle, VoidCallback onTap) {
    return InkWell(
      onTap: onTap, // 添加点击事件处理函数，例如导航到另一个页面或执行其他操作
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            // 左侧主标题
            Text(title, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.normal)),
            // 右侧内容（副标题+箭头）
            Row(
              children: [
                if (subtitle.isNotEmpty)
                  Padding(
                    padding: const EdgeInsets.only(right: 8),
                    child: Text(subtitle, style: TextStyle(fontSize: 14, color: Colors.grey[600])),
                  ),
                const Icon(Icons.chevron_right, color: Colors.grey, size: 20),
              ],
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildSwitchItem(String title, {bool switchValue = false, ValueChanged<bool>? onChanged}) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
      child: Row(
        children: [
          // 标题文本
          Expanded(
            child: Text(title, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.normal)),
          ),
          // 右侧控件
          CupertinoSwitch(
            value: switchValue,
            onChanged: onChanged,
            activeTrackColor: const Color(0xFF377E8E), // 自定义开启状态颜色
          ),
        ],
      ),
    );
  }
}
